﻿class Utils
{
    static function DarkColor(oldcolor:Number,dark:Number):Number
    {
        //求暗色
        var r,g,b;
        if(oldcolor.toString(16).length<6){//防止这个十六进制数的第一位为0;
            r = parseInt("0x0"+substring(oldcolor.toString(16), 0, 1));
            g = parseInt("0x"+substring(oldcolor.toString(16), 2, 2));
            b = parseInt("0x"+substring(oldcolor.toString(16), 4, 2));
        }else{
            r = parseInt("0x"+substring(oldcolor.toString(16), 0, 2));
            g = parseInt("0x"+substring(oldcolor.toString(16), 3, 2));
            b = parseInt("0x"+substring(oldcolor.toString(16), 5, 2));
        }
        r=Math.round(r/dark).toString(16);
        g=Math.round(g/dark).toString(16);
        b=Math.round(b/dark).toString(16);
        //trace("新rgb:"+r+":"+g+":"+b);
        r.length==1 ? r="0"+r:r;
        g.length==1 ? g="0"+g:g;
        b.length==1 ? b="0"+b:b;
        
        var hicolor:Number;
        hicolor = parseInt("0x"+r.toString(16)+""+g.toString(16)+""+b.toString(16));
        r = parseInt("0x"+substring(hicolor.toString(16), 0, 2));
        g = parseInt("0x"+substring(hicolor.toString(16), 3, 2));
        b = parseInt("0x"+substring(hicolor.toString(16), 5, 2));
        return hicolor;
    }
    
    static function GetDayNumber(dt1:Date,dt2:Date):Number
    {
        return (dt1-dt2)/(24*3600*1000);
    }
    
    static function StrToDate(datestr:String):Date
    {
        var lst : Array = datestr.split("-");
        var year : Number = Number(lst[0]);
        var month : Number = Number(lst[1]) - 1;	//月份对于flash，似乎从0开始
		
        var day : Number = Number(lst[2]);
        var dt  = new Date(year,month,day);

        return dt;
    }
	
	static function DateToStrNoDay(dt:Date) : String
	{
		var year:Number = dt.getYear() + 1900;
		var month:Number = dt.getMonth() + 1;

		return year.toString() + "/" + month.toString() ;
	}
	
	static function DateToXStr(dt:Date) : String 
	{
		var tmpYear:Number = dt.getYear();
		var year:Number = tmpYear > 100 ? tmpYear-100 : tmpYear;
		var month:Number = dt.getMonth() + 1 ;		//月份对于flash，似乎从0开始
		var day:Number = dt.getDate();
		var headYear:String = year > 10 ? "" : "0";
		
		return headYear + year.toString() + "/" + month.toString() + "/" + day.toString() ;
	}
	
	static function GetDate(startDate:Date, migrationDay:Number) : Date
	{
		var startDateNum:Number = startDate.getTime();
		return new Date(startDateNum + migrationDay*24*3600*1000);
	}    
}